using UnityEngine;
using System.Collections;

public class FlyingLittle : Ennemy 
{
	public AudioClip[] ambientSound;
	
	private int m_number = 0;
	public int number
	{
		get	{ return m_number; } 
		set { m_number = value; }
	}
	
	new protected void FixedUpdate()
	{
		rigidbody.MovePosition(rigidbody.position - Vector3.right * LevelGenerator.sSpeed * 0.7f * Time.fixedDeltaTime);
	}
	
	protected override void PostSpawnProcess ()
	{	
		int lRand = Random.Range(0, ambientSound.Length);
		
		GetComponent<EnnemySound>().SetAmbient(ambientSound[lRand], 1.0f, 3.0f, 1.0f);
		
		if(m_number == 0)
		{//first spawned
			transform.position = new Vector3(transform.position.x, mWalkableRect.Bottom + 2.0f, transform.position.z);
			
			for(int i = 1; i < 5; i++)
			{
				GameObject lObj = Instantiate(gameObject, transform.position, transform.rotation) as GameObject;
				lObj.GetComponent<FlyingLittle>().number = i;
				lObj.GetComponent<FlyingLittle>().Spawned(mUntouchedRange);
			}
		}
		else
		{
			Vector3 lTargetPos = new Vector3(	transform.position.x + collider.bounds.size.x * m_number, 
		                      					(mWalkableRect.Bottom+ 2.0f) + m_number * ((mWalkableRect.Top - mWalkableRect.Bottom)/5.0f), 
		                      					transform.position.z);
			
			transform.position = lTargetPos;
		}
	}
	
	public void SetNumber(int pNumber)
	{
		
	}
}
